package com.mhd.databases.web;

import com.mhd.databases.common.ResultEnum;
import com.mhd.databases.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/** @author dmh96 */
@RestController
public class TestController {
    @Autowired
    @Qualifier("oneJdbcTemplate")
    JdbcTemplate jdbcTemplate1;

    @Autowired
    @Qualifier("twoJdbcTemplate")
    JdbcTemplate jdbcTemplate2;

    @RequestMapping("/getDataFromMysql")
    public List getDataFromMysql() {
        String sql =
                "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'test' AND table_name = 'test'";
        List list = jdbcTemplate1.queryForList(sql);
        return list;
    }

    @RequestMapping("/getDataFromOracle")
    public List getDataFromOracle() {
        String sql = "SELECT * FROM TEST";
        List list = jdbcTemplate2.queryForList(sql);
        return list;
    }

    @Autowired
    TestService testService;

    @RequestMapping("/test")
    public String test() {
        String code =  testService.test();
        if(ResultEnum.SUCCESS.getCode().equalsIgnoreCase(code)){
            return ResultEnum.SUCCESS.getMsg();
        }
        return ResultEnum.FAILED.getMsg();
    }
}
